//
//  InputViewController.m
//  JiuLe
//
//  Created by 黄鑫 on 16/9/2.
//  Copyright © 2016年 Fine. All rights reserved.
//

#import "InputViewController.h"
#import "NSString+Check.h"

@interface InputViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textFieldInput;

@end

@implementation InputViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"输入";
    [self showNavBarWithRightTitle:@"确定"
                    andRightAction:@selector(sure)
                     andLeftAction:@selector(backAction)
                       andFontSize:17
                     andRightWidth:40];
    if (_inputStyle == InputStyleContactsOne) {
        _textFieldInput.placeholder = @"请输入紧急联系人1姓名";
    }else if (_inputStyle == InputStylePhoneOne){
        _textFieldInput.placeholder = @"请输入紧急联系人1手机号";
        _textFieldInput.keyboardType = UIKeyboardTypeNumberPad;
    }else if (_inputStyle == InputStyleContactsTwo){
        _textFieldInput.placeholder = @"请输入紧急联系人2姓名";
    }else{
        _textFieldInput.placeholder = @"请输入紧急联系人2手机号";
        _textFieldInput.keyboardType = UIKeyboardTypeNumberPad;
    }
}

#pragma mark - 内部方法
- (void)sure{
    if (![_textFieldInput.text isEqualToString:@""] && _textFieldInput != nil) {
        if (_inputStyle == InputStyleContactsOne) {
            if(![_textFieldInput.text checkUserPassword]){
                TIPSFORVIEW(@"紧急联系人1姓名格式不正确");
                return;
            }
        }else if (_inputStyle == InputStylePhoneOne){
            if (![_textFieldInput.text checkPhoneNumInput]) {
                TIPSFORVIEW(@"紧急联系人1手机号格式不正确");
                return;
            }
        }else if (_inputStyle == InputStyleContactsTwo){
            if(![_textFieldInput.text checkUserPassword]){
                TIPSFORVIEW(@"紧急联系人2姓名格式不正确");
                return;
            }
        }else{
            if (![_textFieldInput.text checkPhoneNumInput]) {
                TIPSFORVIEW(@"紧急联系人2手机号格式不正确");
                return;
            }
        }
        if ([self.delegate respondsToSelector:@selector(backInputText: with:)]) {
            [self.delegate backInputText:_textFieldInput.text with:_inputStyle];
        }
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
